/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Planilla_View_Grid.java
 *
 * Created on 3/05/2012, 11:58:55 PM
 */
package v;

import c.GridTableController;
import com.lowagie.text.Font;
import core.constructor.constructor;
import java.awt.Color;
import java.util.Date;
import tools.TextPrompt;

/**
 *
 * @author Usuario
 */
public class Planilla_View_Grid extends javax.swing.JPanel {

    constructor c;
    GridTableController configTable;
    
    private String sqlGeneral = 
            "SELECT id_planilla_horario as id , nombres as nombres, apellidos as apellidos, "
            + "identificacion as identificacion, fecha_agendada as fecha, "
            + "hora_inicio as inicio, hora_fin as fin "
            + "FROM medico natural join planilla_horario"
            + " where fecha_agendada >= '%s'";
    
    private String nombreColumnas =
            "Id, Nombres,Apellidos ,Identificacion,Fecha Agendada,Hora inicio,Hora final,Consultar,Modificar,Eliminar";
    
    /** Creates new form Planilla_View_Grid */
    public Planilla_View_Grid(constructor e) {
        initComponents();
        config(e);
        
        String sqlSelect= String.format(sqlGeneral, new Date());
        
        configTable = new GridTableController(tabla);
        tabla = configTable.setTabla(tabla, sqlSelect, nombreColumnas, c);
        configTable.setFilter(jSearch);
        //desde aca arriba se llama al metodo de clase o al estatico, y se le pasa el campo y ya!
        tabla.setName("Planilla");
        setEstilo();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jSearch = new javax.swing.JTextField();
        jxFecha = new org.jdesktop.swingx.JXDatePicker();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new org.jdesktop.swingx.JXTable();

        jButton1.setText("Agregar a planilla");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSearchActionPerformed(evt);
            }
        });

        jxFecha.setFormats("dd-MM-yyyy");
        jxFecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxFechaActionPerformed(evt);
            }
        });

        jLabel1.setText("Fecha a partir...");

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tabla);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 918, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jxFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        c.constructor("Planilla_View_Add" , "INSERT" , "" );
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSearchActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jSearchActionPerformed

    private void jxFechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxFechaActionPerformed
        // TODO add your handling code here:
        String sqlSelect = String.format(sqlGeneral, jxFecha.getDate());

        configTable = new GridTableController(tabla);
        tabla = configTable.setTabla(tabla, sqlSelect, nombreColumnas, c);
        configTable.setFilter(jSearch);
        //desde aca arriba se llama al metodo de clase o al estatico, y se le pasa el campo y ya!
        tabla.setName("Planilla");
    }//GEN-LAST:event_jxFechaActionPerformed

    private void config(constructor e) {
        this.c = e;
        
        //Configurar tabla BD
        System.setProperty("tabla_bd", "planilla_horario");

        /*
         * Configurar Accion Boton Eliminar
         * UPDATE = Cambiar de Estado a Inactivo (0)
         * DELETE = ELiminar de la Tabla el Registro
         */
        System.setProperty("accion_eliminar", "DELETE_PLANILLA");
        
        c.setLabelModulo("Planillas");
        c.setLabelAccion("Medicos agendados");
        c.setNavegar("Planilla_View_Grid");
    }
    
    private void setEstilo() {
        TextPrompt placeHolder = new TextPrompt("Buscar Planilla", jSearch);
        placeHolder.setForeground(Color.blue);
        placeHolder.changeAlpha(0.5f);
        placeHolder.changeStyle(Font.BOLD + Font.ITALIC);
        placeHolder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/search24.gif")));
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jSearch;
    private org.jdesktop.swingx.JXDatePicker jxFecha;
    private org.jdesktop.swingx.JXTable tabla;
    // End of variables declaration//GEN-END:variables
}
